package com.service.scheduling.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.service.dao.constants.ConfigConstants;
import com.service.dao.mapper.SysConfigMapper;
import com.service.dao.model.SysConfig;
import com.service.scheduling.service.SysConfigService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Map;

/**
 * <dl>
 * <dt>back-end</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年08月01日</dd>
 * </dl>
 *
 * @author
 */
@Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {

    @Override
    public SysConfig getByGroupAndName(Integer group, String name) {
        Map<String, Object> param = Maps.newHashMap();
        if(!ObjectUtils.isEmpty(group)){
            param.put("conf_group", group);
        }
        param.put("conf_name", name);
        param.put("conf_status", 1);
        List<SysConfig> configList = baseMapper.selectByMap(param);
        if(!ObjectUtils.isEmpty(configList)){
            return configList.get(0);
        }
        return null;
    }

    @Override
    public SysConfig getEthNodeConfig(){
        return getByGroupAndName(ConfigConstants.Group.wallet.getCode(),ConfigConstants.ETH_NODE_RPC);
    }

    @Override
    public SysConfig getByName(String name) {
        return getByGroupAndName(null, name);
    }
}
